home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / sample code / overview / dtscpluslibrary / sources / tracertest.cp < prev    next >
Encoding:
Text File  |  2000-09-28  |  2.1 KB  |  79 lines

  1. /*
  2.     File:        tracertest.cp
  3.  
  4.     Contains:    TTracer is an example of a stack/heap based tracing class, which could be
  5.                   used for tracing memory leaks and keeping track of created objects
  6.                   TestTracer.cp contains test code for testing the TTracer class.
  7.  
  8.     Written by: Kent Sandvik    
  9.  
  10.     Copyright:    Copyright Â© 1992-1999 by Apple Computer, Inc., All Rights Reserved.
  11.  
  12.                 You may incorporate this Apple sample source code into your program(s) without
  13.                 restriction. This Apple sample source code has been provided "AS IS" and the
  14.                 responsibility for its operation is yours. You are not permitted to redistribute
  15.                 this Apple sample source code as "Apple sample source code" after having made
  16.                 changes. If you're going to re-distribute the source, we require that you make
  17.                 it clear in the source that the code was descended from Apple sample source
  18.                 code, but that you've made changes.
  19.  
  20.     Change History (most recent first):
  21.                 8/18/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  22.                 
  23.  
  24. */
  25.  
  26. // Include files
  27. #ifndef _TRACER_
  28. #include "Tracer.h"
  29. #endif
  30. void InvertPermutation(int* perm,
  31.                        int* inv,
  32.                        int max);
  33. // Function used for testing TTracer.
  34. void InvertPermutation(int* perm,
  35.                        int* inv,
  36.                        int max)
  37. {
  38.     TTracer autoTracer("InvertPermutation function", TRACEPOINT);
  39.  
  40.     if (perm && (new TTracer("temp", TRACEPOINT))// show TTracer in action
  41.         && inv && (new TTracer("temp2", TRACEPOINT))// these two are never destructed =
  42.         && (max > 0))                            // memory leak!
  43.     {
  44.         TTracer otherTracer("otherTracer", TRACEPOINT);
  45.  
  46.         for (int i = 0; i < max; i++)
  47.         {
  48.             TTracer thirdTracer("iterationTracing...", TRACEPOINT);
  49.             inv[perm[i]] = i;
  50.         }
  51.     }
  52. }
  53.  
  54.  
  55. // Test code itself.
  56. void main(void)
  57. {
  58.     cout << "The TTracer test is starting…\n";
  59.  
  60.     // Array declarations used in the test
  61.     int perm[] = {
  62.                   1, 2, 3, 6, 7};
  63.     int max = 5;
  64.  
  65.     int* inv = new
  66.               int[max];
  67.     InvertPermutation(&perm[0], inv, max);
  68.  
  69.     cout << "The TTracer test ended!\n";
  70. }
  71.  
  72. // _________________________________________________________________________________________________________ //
  73.  
  74.  
  75. /*    Change History (most recent last):
  76.   No        Init.    Date        Comment
  77.   1            khs        7/10/92        New file
  78. */
  79.